﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.AutomaticPathPlanner.Planner.CApAPPSegmentNewFullCTOCommand
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections.Generic;


namespace DnProcessSimulateCommands.AutomaticPathPlanner.Planner;

internal class CApAPPSegmentNewFullCTOCommand(
  CApAPPTask i_task,
  KiAppPathPlanningParamsEx i_pathPlanningParams) : CApAPPSegmentCTOCommand(i_task, i_pathPlanningParams)
{
  private KiAppCycleTimeOptimizationResultEx m_optimizationResult;

  public bool HasInitialCycleTime => this.m_optimizationResult.HasInitialCycleTime;

  public double InitialCycleTime => this.m_optimizationResult.InitialCycleTime;

  public double ResultCycleTime => this.m_optimizationResult.ResultCycleTime;

  public KiAppCycleTimeOptimizationStatus OptimizationStatus
  {
    get => this.m_optimizationResult.OptimizationStatus;
  }

  public bool HasSkippedCollidingSegments => this.m_optimizationResult.HasSkippedCollidingSegments;

  protected override bool DoStartPlanning(
    CApAPPTask i_task,
    KiAppPathPlanningParamsEx i_params,
    ref bool o_shouldContinue,
    ref List<string> o_errorMessages)
  {
    if (i_task is CApAPPRoboticTask capAppRoboticTask && CApAPPUtilities.IsRobotConnectedToRCS(capAppRoboticTask.Robot))
      i_params.IsRcsActivated = true;
    return KiAppSegmentOptimizeNewFullCtoTrajectoryCommandEx.StartOptimize(i_task.KiTask, i_params, ref o_shouldContinue, ref o_errorMessages);
  }

  protected override void DoEndPlanning(CApAPPTask i_task, bool i_success)
  {
    this.m_optimizationResult = KiAppSegmentOptimizeNewFullCtoTrajectoryCommandEx.EndOptimizeAndGetResult(i_task.KiTask, i_success);
  }

  protected override bool DoContinuePlanning(CApAPPTask i_task, ref bool o_shouldContinue)
  {
    return KiAppSegmentOptimizeNewFullCtoTrajectoryCommandEx.ContinueOptimize(i_task.KiTask, ref o_shouldContinue);
  }

  protected override double DoGetProgress(CApAPPTask i_task)
  {
    return KiAppSegmentOptimizeNewFullCtoTrajectoryCommandEx.GetProgress(i_task.KiTask);
  }

  public bool GetCurrentResult(ref double o_currentResult)
  {
    return KiAppSegmentOptimizeNewFullCtoTrajectoryCommandEx.GetCurrentResult(this.taskToPlan.KiTask, ref o_currentResult);
  }

  public void GetTimeOutReached(ref bool o_isTimeOutReached)
  {
    o_isTimeOutReached = KiAppSegmentOptimizeNewFullCtoTrajectoryCommandEx.GetTimeOutReached(this.taskToPlan.KiTask);
  }
}
